package com.swordget.entity.vo;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.swordget.entity.TableDesign;
import com.swordget.exception.VerifyFailException;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @Author: David
 * @Date: Created in 14:17 2020/4/9
 * @Description: 表单请求vo 类
 * @Modified By:
 * @Version: 0.0.1
 */
@Data
@ToString
public class FromRequestVo<T> {

    /**
     * 记录表结构相关信息
     */
    private TableDesign table;

    /**
     * 记录表单数据信息
     */
    private List<T> result;

    private String dataStatus;

    /**
     * 不通过原因
     */
    private String notPassMark;

    /**
     * 封装查询条件
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String searchParams;

    @JsonIgnore
    private JSONArray queryParams;

    public JSONArray getQueryParams() {
        if (this.queryParams == null && StringUtils.isNotBlank(searchParams)) {
            try {
                this.queryParams = JSONObject.parseArray(searchParams);
            } catch (Exception e) {
                throw new VerifyFailException("请检查您的参数!", e);
            }
            this.searchParams = null;
        }
        return this.queryParams;
    }


}
